package ComparableAndComparator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Employee implements Comparable<Employee> {
	private int empId;
	private String name;
	private int age;

	public Employee(int empId, String name, int age) {
	this.empId=empId;
	this.name=name;
	this.age=age;
	}
	
	@Override
	public int compareTo(Employee o) {
		return o.empId - this.empId ;
	}

	public int getEmpId() {
		return empId;
	}

	public void setEmpId(int empId) {
		this.empId = empId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}


}

class Utiles {

	public static List<Employee> getEmployees() {
		List<Employee> col = new ArrayList<Employee>();
		
		col.add(new Employee(5, "Frank", 28));
		col.add(new Employee(1, "Jorge", 19));
		col.add(new Employee(6, "Bill", 34));
		col.add(new Employee(3, "Michel", 10));
		col.add(new Employee(7, "Simpson", 8));
		col.add(new Employee(4, "Clerk",16 ));
		col.add(new Employee(8, "Lee", 40));
		col.add(new Employee(2, "Mark", 30));
		
		return col;
	}
}


class EmpSortByName implements Comparator<Employee>{

	public int compare(Employee o1, Employee o2) {
		return o1.getName().compareTo(o2.getName());
	}
}


class TestEmployeeSort {

	public static void main(String[] args) {     
		List coll = Utiles.getEmployees();
		//Collections.sort(coll); // sort method
		Collections.sort(coll, new EmpSortByName());
		printList(coll);
	}

	private static void printList(List<Employee> list) {
		System.out.println("EmpId\tName\tAge");
		for (Employee e: list) {
			System.out.println(e.getEmpId() + "\t" + e.getName() + "\t" + e.getAge());
	}
}
}
